package com.kabuda.zhugehot200_review;

/**
 * @author kabuda
 * @date 2025-03-16 16:18
 * @description
 */
public class t11_二叉树的最小深度 {
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(5);
        TreeNode treeNode6 = new TreeNode(6);
        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;

        treeNode3.left = treeNode4;
        treeNode4.left = treeNode5;

        System.out.println(dfs(treeNode1));
        System.out.println(bfs(treeNode1));
    }


    /**
     * @param root
     * @author kabuda
     * @date 2025/3/16 16:36
     * @description 深度优先遍历
     */
    public static int dfs(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null || root.right == null) {
            return 1;
        }

        int min = Integer.MAX_VALUE;
        if (root.left != null) {
            min = Math.min(dfs(root.left), min) + 1;
        }
        if (root.right != null) {
            min = Math.min(dfs(root.right), min) + 1;
        }

        return min;
    }

    /**
     * @param root
     * @author kabuda
     * @date 2025/3/16 16:36
     * @description 广度优先遍历
     */
    public static int bfs(TreeNode root) {
        return 0;
    }


    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


}
